import { reactive, ref, toRefs } from 'vue';
import { postExit, getImageData } from '@/service/getInfo';

interface CheckListItem {
  program: string;
  flag: boolean;
}
interface MyListItem {
  program: string;
  flag: boolean;
}
export interface CheckData {
  imageUrl: any
}
export const useListData = () => {
  const lists = reactive<CheckListItem[]>([

    { program: '刺毛条检测', flag: false },
    { program: 'pmp检测', flag: false },
    { program: '塑料封条检测', flag: false },
    { program: '黑色三角无纺布检测', flag: false },
    { program: '塑料卡条检测', flag: false },
  ]);
  const ing = ref(false);
  const beforeTest = ref(true);
  // 检测结果
  const result =ref(false);
  const changeBeforeTest = () => {
    ing.value = !ing.value;
    postExit("测试").then((res) => {
      setTimeout(() => {
        console.log(res.beforeTest);
        result.value = res.result;
        beforeTest.value = res.beforeTest;
        lists[0].flag = res.my_list.刺毛条;
        console.log("cimaotiao", res.my_list.刺毛条)
        lists[1].flag = res.my_list.pwp;
        lists[2].flag = res.my_list.塑料封条;
        lists[3].flag = res.my_list.黑色三角无纺布;
        lists[4].flag = res.my_list.塑料卡条;
        console.log('ok');
      }, 200);
    }).catch((error) => {
      console.error(error);
    });
  };


  const checkData = reactive<CheckData>({
    imageUrl: ''
  })
  const fetchImage = async () => {
    try {
        const res = await getImageData();
        console.log(res);
        checkData.imageUrl = res;
    } catch (error) {
        console.error(error);
    }
};

  return {
    ing,
    beforeTest,
    result,
    lists,
    fetchImage,
    checkData,
    changeBeforeTest,
  };
};